<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form :form="form" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-item label="案件编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['ajbh']" placeholder="请输入案件编号"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="上报时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择上报时间" v-decorator="['sbsj']" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="上报人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['sbr']" placeholder="请输入上报人"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="案件来源" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['ajly']" placeholder="请输入案件来源"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="案件类别" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['ajlb']" placeholder="请输入案件类别"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="大类名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['dlmc']" placeholder="请输入大类名称"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="小类名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['xlmc']" placeholder="请输入小类名称"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="案件状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['ajzt']" placeholder="请输入案件状态"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="案件描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-textarea v-decorator="['ajms']" rows="4" placeholder="请输入案件描述" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="案件地点" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-textarea v-decorator="['ajdd']" rows="4" placeholder="请输入案件地点" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="所属区域" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['ssqy']" placeholder="请输入所属区域"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="所属街道" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['ssjd']" placeholder="请输入所属街道"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="所属网格" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['sswg']" placeholder="请输入所属网格"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="责任网格" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zrwg']" placeholder="请输入责任网格"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="处置截至时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择处置截至时间" v-decorator="['czjzsj']" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="当前阶段" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['dqjd']" placeholder="请输入当前阶段"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="结案类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['jalx']" placeholder="请输入结案类型"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="结案意见" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-textarea v-decorator="['jayj']" rows="4" placeholder="请输入结案意见" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="案件图片" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-image-upload isMultiple  v-decorator="['ajtp']" ></j-image-upload>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="经度" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['lng']" placeholder="请输入经度"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="纬度" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['lat']" placeholder="请输入纬度"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="结案时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择结案时间" v-decorator="['jasj']" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="结案人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['jar']" placeholder="请输入结案人"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
            <a-button @click="submitForm">提 交</a-button>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ZrCgztJrajXxForm',
    components: {
    },
    props: {
      //流程表单data
      formData: {
        type: Object,
        default: ()=>{},
        required: false
      },
      //表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/visual/zrCgztJrajXx/add",
          edit: "/visual/zrCgztJrajXx/edit",
          queryById: "/visual/zrCgztJrajXx/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return true
          }
        }
        return false
      }
    },
    created () {
      //如果是流程中表单，则需要加载流程表单data
      this.showFlowData();
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'ajbh','sbsj','sbr','ajly','ajlb','dlmc','xlmc','ajzt','ajms','ajdd','ssqy','ssjd','sswg','zrwg','czjzsj','dqjd','jalx','jayj','ajtp','lng','lat','jasj','jar'))
        })
      },
      //渲染流程表单数据
      showFlowData(){
        if(this.formBpm === true){
          let params = {id:this.formData.dataId};
          getAction(this.url.queryById,params).then((res)=>{
            if(res.success){
              this.edit (res.result);
            }
          });
        }
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'ajbh','sbsj','sbr','ajly','ajlb','dlmc','xlmc','ajzt','ajms','ajdd','ssqy','ssjd','sswg','zrwg','czjzsj','dqjd','jalx','jayj','ajtp','lng','lat','jasj','jar'))
      },
    }
  }
</script>